import numpy as np
import scipy as sp

uci = sp.io.loadmat("UCIHAR_Train.mat")
motion = sp.io.loadmat("MotionSense_Train.mat")
usc = sp.io.loadmat("USCHAD_Train.mat")

uci["train_y"] -= 1
motion["train_y"] -= 1
usc["train_y"] -= 1

train_X = np.concatenate((uci["train_X"], motion["train_X"], usc["train_X"]), axis=0)
train_y = np.concatenate((uci["train_y"], motion["train_y"], usc["train_y"]), axis=0)

mean_X = train_X.mean(axis=(0, 1), keepdims=True)
std_X = train_X.std(axis=(0, 1), keepdims=True)
print("Mean:", np.squeeze(mean_X), sep="\n")
print("Std:", np.squeeze(std_X), sep="\n")
train_X = (train_X - mean_X) / std_X

# min_X = train_X.mean(axis=(0, 1), keepdims=True)
# max_X = train_X.max(axis=(0, 1), keepdims=True)
# print("Min", np.squeeze(min_X), sep="\n")
# print("Max", np.squeeze(max_X), sep="\n")
# train_X = (train_X - min_X) / (max_X - min_X)

import torch

torch.save(
    {
    "train_X": torch.tensor(train_X, dtype=torch.float32),
    "train_y": torch.tensor(train_y, dtype=torch.long)
    },
    "combined_train_dataset.pt"
)
